﻿@{
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}
<form class="layui-form layui-form-pane">
    <div id="view">

    </div>
    <div class="layui-form-item">
        @*<button id="export" type="button" class="layui-btn">导出</button>*@
        <button type="button" class="layui-btn" lay-submit lay-filter="save">保存</button>
        <button type="button" class="layui-btn layui-btn-primary" id="btnCancel">取消</button>
    </div>
</form>
@section scripts{
<script id="demo" type="text/html">
    {{# var i=1; layui.each(d.zd, function(index, item){ }}
        {{#  if(d.zdn[index]==""){ }}
    <div class="layui-form-item" style="width:100%">
        <label class="layui-form-label" style="width:10%">{{i++}}</label>
        <label class="layui-form-label" style="width:18%">{{d.tbn[index]}}</label>
        <label class="layui-form-label" style="width:18%">{{d.zd[index]}}</label>
        <div class="layui-input-inline" style="width:30%">
            <input type="text" name="{{d.tbn[index]}}_{{d.zd[index]}}" placeholder="请填写字段描述" autocomplete="off" class="layui-input"  value="">
        </div>
        @*<div class="layui-input-inline">
            <input type="text" name="{{d.zd[index]}}" placeholder="请填写字段描述" autocomplete="off" class="layui-input" style="width:700px;" value="">
        </div>*@
    </div>
        {{#  } }}
    {{#  }); }}
</script>
    <script type="text/javascript">
        var strContent = "";
        var strPhone = "";
        var $, layer;
        layui.use(['form','laytpl'], function () {
            var form = layui.form,
                laytpl = layui.laytpl;
            $ = layui.jquery;
            layer = parent.layer === undefined ? layui.layer : parent.layer;

            var getTpl = demo.innerHTML;
            var view = document.getElementById('view');
            var data = {"zd":@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.zd)),
                "zdn":@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.zdn)),
                "zdc":@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.zdc)),
                "tbn":@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.tbn))};
            laytpl(getTpl).render(data, function (html) {
                view.innerHTML = html;
            });

            // 监听关闭
            $('#btnCancel').on('click', function () {
                layer_close();
            });
            //保存
            @*$('#export').on('click', function () {
                var loading =0;
                loading= layer.load();
                $.post("@Url.Action("Export", "Dictionary")", { db: '@ViewBag.db', table: '@ViewBag.table' }, function (res) {
                    layer.msg("导出成功");
                    //var url="/Upload/BankTB636667529745244544.xls";
                    window.location.href="/bgFile/File/excel/"+res.data;
                    layer.close(loading);
                    $.post("@Url.Action("DeleteFile", "Dictionary")",{address:res.msg},function(res){

                    });
                        });
            });*@

            form.on('submit(save)', function(data){
                //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                var name = "", douhao = "";
                var name1 = "", douhao1 = "";
                var name2 = "", douhao2 = "";
                var zd=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.zd));
                var tbn=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.tbn));
                var k=0;
                @*var zdc=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.zdc));*@
                //console.log(data.field);
                if(@ViewBag.tag==1){
                    for(let i in data.field){
                        var value=data.field[i];
                        if(value.length!=0||value!=""){//判断是否填写说明
                            name += douhao + value; douhao = ',';//获得描述内容
                            name1 += douhao1 + zd[k]; douhao1 = ',';//获得对应列名称
                            name2 += douhao2 + tbn[k]; douhao2 = ',';//获得表名称
                            k++;
                            continue;
                        }
                        k++;
                    }
                    //console.log(data.field);
                    //console.log(name);
                    //console.log(name1);
                    //console.log(name2);
                }
                else{
                    for(let i in data.field){
                        var value=data.field[i];
                        if(value.length!=0||value!=""){//判断是否填写说明
                            name += douhao + value; douhao = ',';//获得填写说明
                            name1 += douhao1 + zd[k]; douhao1 = ',';//获得填写说明
                            k++;
                            continue;
                        }
                        k++;
                    }
                }
                var loadindex=layer.load();
                $.post("@Url.Action("Save", "Dictionary")", {name:name,name1:name1,name2:name2,
                    table:"@ViewBag.table",db:"@ViewBag.db"},
                    function (result) {
                        layer.msg("保存成功");
                        layer.close(loadindex);
                        layer_close();
                        parent.layui.table.reload('tbList');
                    });
            });
        });
    </script>
}

